package com.lanhe.admin.controller.packageManage;

import com.lanhe.common.annotation.Log;
import com.lanhe.common.constant.Constants;
import com.lanhe.common.core.controller.BaseController;
import com.lanhe.common.core.domain.AjaxResult;
import com.lanhe.common.core.page.TableDataInfo;
import com.lanhe.common.enums.BusinessType;
import com.lanhe.pckageManage.domain.LhPackageManage;
import com.lanhe.pckageManage.service.ILhPackageManageService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 包管理(LhPackageManage)表控制层
 *
 * @author zhanggl
 * @since 2023-12-02 22:51:11
 */
@RestController
@RequestMapping("packageManage")
public class LhPackageManageController extends BaseController {

	/**
	 * 服务对象
	 */
	@Resource
	private ILhPackageManageService lhPackageManageService;

	/**
	 * 分页查询所有数据
	 */
	@PreAuthorize("@ss.hasPermi('packageManage:list')")
	@GetMapping("/list")
	public TableDataInfo list(LhPackageManage packageManage) {
		startPage();
		List<LhPackageManage> list = lhPackageManageService.selectIdentifierBindList(packageManage);
		for (LhPackageManage lhPackageManage : list) {
			lhPackageManage.setIsPopularName(lhPackageManage.getIsPopular().equals(Constants.GeneralIntType.ONE) ? "是" : "否");
		}
		return getDataTable(list);
	}


	/**
	 * 新增
	 *
	 * @param packageManage 实体
	 * @author zhanggl
	 * @date 2023/12/4
	 */
	@PreAuthorize("@ss.hasPermi('packageManage:add')")
	@Log(title = "APP包管理", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@Validated @RequestBody LhPackageManage packageManage) {
		return toAjax(lhPackageManageService.insertPackageManage(packageManage));
	}

	/**
	 * 查询单个
	 *
	 * @param packageId 包ID
	 * @author zhanggl
	 * @date 2023/12/4
	 */
	@PreAuthorize("@ss.hasPermi('packageManage:query')")
	@GetMapping(value = "/{packageId}")
	public AjaxResult getInfo(@PathVariable Long packageId)
	{
		if (null == packageId){
			return error("ID不能为空");
		}
		return success(lhPackageManageService.selectPackageManageById(packageId));
	}

	/**
	 * 修改
	 *
	 * @param packageManage 实体
	 * @author zhanggl
	 * @date 2023/12/4
	 */
	@PreAuthorize("@ss.hasPermi('packageManage:edit')")
	@Log(title = "APP包管理", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@Validated @RequestBody LhPackageManage packageManage) {
		if (null == packageManage.getPackageId()){
			return error("ID不能为空");
		}
		return toAjax(lhPackageManageService.updatePackageManage(packageManage));
	}

	/**
	 * 删除
	 *
	 * @param packageId 包ID
	 * @author zhanggl
	 * @date 2023/12/4
	 */
	@PreAuthorize("@ss.hasPermi('packageManage:remove')")
	@Log(title = "APP包管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{packageId}")
	public AjaxResult remove(@PathVariable Long packageId)
	{
		if (null == packageId){
			return error("ID不能为空");
		}
		return toAjax(lhPackageManageService.deletePackageManageById(packageId));
	}
}

